package com.cy.pj.sys.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.sys.pojo.SysRole;
import com.cy.pj.sys.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张琪
 * @date 2020/11/16
 * @describe
 */

@RequestMapping("/role/")
@RestController
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @RequestMapping("doFindPageObjects")
    public JsonResult doFindPageObjects(String name, Integer pageCurrent){
        return new JsonResult(sysRoleService.findPageObjects1(name, pageCurrent));
        /*是谁将对象转换为json格式的字符串
        * jackson(jackson 会通过json对象所有的getxx()方法来进行字符串转化)
        *  在这个字符串底层,通过什么方式来给字符串赋值
        * get方法(getXXX()方法的xxx作为key值, 返回值作为value)
        *
        *
        * */
    }

    @RequestMapping("doSaveObject")
    public JsonResult doSaveObject(SysRole sysRole, Integer[] menuIds){
        int rows = sysRoleService.saveObject(sysRole, menuIds);
        if(rows == 0){
            return new JsonResult("insert fault");
        }
        return new JsonResult("insert success");
    }


    @RequestMapping("doFindObjectById")
    public JsonResult doFindById(Integer id){
        return new JsonResult(sysRoleService.findById(id));
    }

    @RequestMapping("doUpdateObject")
    public JsonResult doUpdateObject(SysRole sysRole, Integer[] menuIds){
        int rows = sysRoleService.updateObject(sysRole, menuIds);
        if(rows == 0){
            return new JsonResult("update fault");
        }
        return new JsonResult("update success");
    }


    @RequestMapping("doFindRoles")
    public JsonResult doFindRoles(){
        return new JsonResult(sysRoleService.findObjects());
    }

    @RequestMapping("doDeleteObject")
    public JsonResult doDeleteObject(Integer id){
        int rows = sysRoleService.doDeleteObject(id);
        if(rows == 0)
            return new JsonResult("delete fault");
        return new JsonResult("delete success");
    }
}
